namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_class3 的摘要说明
/// </summary>
public class t_class3:IEntityUtil
{
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Class3 __class3;
	public long seqID  
	{
		get{return __class3.seqID;}
		set{ __class3.seqID=value;}
	}
	public String name  
	{
		get{return __class3.name;}
		set{ __class3.name=value;}
	}
	public long parentSeqID  
	{
		get{return __class3.parentSeqID;}
		set{ __class3.parentSeqID=value;}
	}
	private static  Class3Dao dao=(Class3Dao)SpringContext.Context.GetObject("Class3Dao");
	public static Class3Dao DAO
	{
		get{return dao;}
		
	}
	
	public t_class3()
	{
		__class3=new Class3();
	  	seqID=consts.long_min;
	  	name="";
	  	parentSeqID=consts.long_min;
	  // dao=(Class3Dao)SpringContext.Context.GetObject("Class3Dao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"编号");
		colNames.Add("seqID");
		m_colLabels.Add("name", @"名称");
		colNames.Add("name");
		m_colLabels.Add("parentSeqID", @"父类编号");
		colNames.Add("parentSeqID");
	  }
	
	}
	public t_class3(Class3 entity )
	{
		__class3=entity;
		
	  // dao=(Class3Dao)SpringContext.Context.GetObject("Class3Dao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"编号");
		colNames.Add("seqID");
		m_colLabels.Add("name", @"名称");
		colNames.Add("name");
		m_colLabels.Add("parentSeqID", @"父类编号");
		colNames.Add("parentSeqID");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Class3));}
     }
	public const string ENTITYNAME="t_class3";
	public const int SEQN0=80;
	
    public void checkAdd()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入编号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("编号是主健，框架要求值不能为0"));				

	
	len=name.Trim().Length;
	if(len>50)
		 throw (new Exception("名称字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("名称不能为空!"));	
	

	//try{Convert.ToInt64(parentSeqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	parentSeqID<consts.long_min+1)
			throw (new Exception("请输入父类编号"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("name", name);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==0)
			return;
		Class3 obj=list[0] as Class3;
//唯一性异常消息抛出
		if( obj.name==name)
		{
			throw (new Exception(string.Format("名称:{0}已经存在",name)));	
		}
	//end unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入编号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("编号是主健，框架要求值不能为0"));				

	
	len=name.Trim().Length;
	if(len>50)
		 throw (new Exception("名称字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("名称不能为空!"));	
	

	//try{Convert.ToInt64(parentSeqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	parentSeqID<consts.long_min+1)
			throw (new Exception("请输入父类编号"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("seqID", seqID);
		crit=Restrictions.Or(crit,Restrictions.Eq("name", name));
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__class3);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByseqID()
    {
    
        try
        {
          dao.Delete(__class3);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__class3);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",seqID)				  ));	
m_updateRow(rowNo,ii++,name);	
		Class2 p0 =((Class2Dao)SpringContext.Context.GetObject("Class2Dao")).Get(
		((Class2Dao)SpringContext.Context.GetObject("Class2Dao")).DC.Add(Restrictions.Eq("seqID",parentSeqID)));
		
		if(p0==null)
			 m_updateRow(rowNo,ii++,				(				  string.Format("{0}",parentSeqID)				  ));
		else
			m_updateRow(rowNo,ii++,p0.name.ToString());
     
    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"编号");
			m_insertHead(ii++,200,"名称");
			m_insertHead(ii++,200,"父类编号");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,				(				  string.Format("{0}",seqID)				  ));
     	m_insertRow(0,ii++,name);
		Class2Dao dao0=(SpringContext.Context.GetObject("Class2Dao") as Class2Dao);
        Class2 p0 =  dao0.Get(dao0.DC.Add(Restrictions.Eq("seqID",parentSeqID)));
		if(p0!=null)
			 m_insertRow(0,ii++,p0.name.ToString());
		else
			m_insertRow(0,ii++,				(				  string.Format("{0}",parentSeqID)				  ));
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"编号");
			m_insertHead(ii++,200,"名称");
			m_insertHead(ii++,200,"父类编号");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Class3 obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.seqID)
				  )
);
m_insertRow(j,ii++,obj.name.ToString());
		Class2Dao dao0=(SpringContext.Context.GetObject("Class2Dao") as Class2Dao);
        Class2 p0 =  dao0.Get(dao0.DC.Add(Restrictions.Eq("seqID",obj.parentSeqID)));
		if(p0!=null)
			 m_insertRow(j,ii++,p0.name.ToString());
		else
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.parentSeqID)
				  )
);

		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Class3 obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__class3=obj;
            	return true;
            }
        
    }
    public static t_class3 Get(DetachedCriteria dc)
    {
    	
    	Class3 obj=((Class3Dao)SpringContext.Context.GetObject("Class3Dao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_class3( obj );
        
    }
	 public static t_class3 GetBySeqID(long val)
	 {
	 	Class3 obj=((Class3Dao)SpringContext.Context.GetObject("Class3Dao"))
	 	.GetBySeqID(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_class3( obj );
	 	
	 	
	 }
	 public  bool InitBySeqID(long val)
	 {
	 	

	 	Class3 obj=dao.GetBySeqID(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__class3=obj;
	 		return true;
	 	}
	 	
	 	
	 }
	 public static t_class3 GetByName(String val)
	 {
	 	Class3 obj=((Class3Dao)SpringContext.Context.GetObject("Class3Dao"))
	 	.GetByName(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_class3( obj );
	 	
	 	
	 }
	 public  bool InitByName(String val)
	 {
	 	

	 	Class3 obj=dao.GetByName(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__class3=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			Controls["seqID"].Text=				(				  string.Format("{0}",seqID)				  );
		}
		if(Controls["name"]!=null)
		{
			Controls["name"].Text=name;
		}
		if(Controls["parentSeqID"]!=null)
		{
			Controls["parentSeqID"].Text=				(				  string.Format("{0}",parentSeqID)				  );
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_class3 Init(Class3 item)
    {
        __class3=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			
			if(Controls["seqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["seqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{seqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("编号格式不正确！！"));
				}
				
			}
			else
			{
				try{seqID=(Controls["seqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["seqID"].Text));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("编号格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["name"]!=null)
		{
			
			if(Controls["name"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["name"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{name=v;}
				catch
				{
					 Controls["name"].Focus();
					throw  (new Exception("名称格式不正确！！"));
				}
				
			}
			else
			{
				try{name=Controls["name"].Text;}
				catch
				{
					 Controls["name"].Focus();
					throw  (new Exception("名称格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["parentSeqID"]!=null)
		{
			
			if(Controls["parentSeqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["parentSeqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{parentSeqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["parentSeqID"].Focus();
					throw  (new Exception("父类编号格式不正确！！"));
				}
				
			}
			else
			{
				try{parentSeqID=(Controls["parentSeqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["parentSeqID"].Text));}
				catch
				{
					 Controls["parentSeqID"].Focus();
					throw  (new Exception("父类编号格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
